home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / id.test < prev    next >
Encoding:
Text File  |  1995-06-23  |  2.6 KB  |  108 lines

  1. # This file is a Tcl script to test out the procedures in the file
  2. # tkId.c, which recycle X resource identifiers.  It is organized in
  3. # the standard fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1995 Sun Microsystems, Inc.
  6. #
  7. # See the file "license.terms" for information on usage and redistribution
  8. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  9. #
  10. # @(#) id.test 1.2 95/06/23 11:16:47
  11.  
  12. if {[info procs test] != "test"} {
  13.     source defs
  14. }
  15.  
  16. foreach i [winfo children .] {
  17.     destroy $i
  18. }
  19. wm geometry . {}
  20. raise .
  21.  
  22. proc mkWindows count {
  23.     set maxId [winfo id .]
  24.     for {set i 1} {$i <= $count} {incr i} {
  25.     button .b$i -text "Button $i"
  26.     pack .b$i
  27.     if {[winfo id .b$i] > $maxId} {
  28.         set maxId [winfo id .b$i]
  29.     }
  30.     }
  31.     return $maxId
  32. }
  33.  
  34. test id-1.1 {WindowIdCleanup, delaying window release} {
  35.     bind all <Destroy> {lappend x %W}
  36.     catch {unset map}
  37.     frame .f
  38.     set j 0
  39.     foreach i {a b c d e f g h i j k l m n o p q} {
  40.     toplevel .f.$i -height 50 -width 100
  41.     wm geometry .f.$i +$j+$j
  42.     incr j 10
  43.     set map([winfo id .f.$i]) .f.$i
  44.     }
  45.     update
  46.     set x {}
  47.     destroy .f
  48.  
  49.     # Destroy events should have occurred for all windows.
  50.     set result [list [lsort $x]]
  51.  
  52.     set x {}
  53.     update idletasks
  54.     set reused {}
  55.     foreach i {a b c d e} {
  56.     set w .${i}2
  57.     frame $w -height 20 -width 100 -bd 2 -relief raised
  58.     pack $w
  59.     if [info exists map([winfo id $w])] {
  60.         lappend reused $map([winfo id $w])
  61.     }
  62.     set map([winfo id $w]) $w
  63.     }
  64.  
  65.     # No window ids should have been reused: stale Destroy events still
  66.     # pending in queue.
  67.     lappend result [lsort $reused]
  68.  
  69.     # Wait a few seconds, then try again;  ids should still not have
  70.     # been re-used.
  71.  
  72.     set y 0
  73.     after 2000 {set y 1}
  74.     tkwait variable y
  75.     foreach i {a b c} {
  76.     set w .${i}3
  77.     frame $w -height 20 -width 100 -bd 2 -relief raised
  78.     pack $w
  79.     if [info exists map([winfo id $w])] {
  80.         lappend reused $map([winfo id $w])
  81.     }
  82.     set map([winfo id $w])] $w
  83.     }
  84.  
  85.     # Ids should not yet have been reused.
  86.     lappend result [lsort $reused]
  87.  
  88.  
  89.     # Wait a few more seconds, to give ids enough time to be recycled.
  90.     set y 0
  91.     after 4000 {set y 1}
  92.     tkwait variable y
  93.     foreach i {a b c d e f} {
  94.     set w .${i}4
  95.     frame $w -height 20 -width 100 -bd 2 -relief raised
  96.     pack $w
  97.     if [info exists map([winfo id $w])] {
  98.         lappend reused $map([winfo id $w])
  99.     }
  100.     set map([winfo id $w])] $w
  101.     }
  102.  
  103.     # Ids should be reused now, due to time delay.  Destroy events should
  104.     # have been discarded.
  105.     lappend result [lsort $reused] [lsort $x]
  106. } {{.f .f.a .f.b .f.c .f.d .f.e .f.f .f.g .f.h .f.i .f.j .f.k .f.l .f.m .f.n .f.o .f.p .f.q} {} {} {.f.m .f.n .f.o .f.p .f.q} {}}
  107. bind all <Destroy> {}
  108.